﻿using System;
using System.Web;
using System.Web.Mvc;

namespace LeadVinaglue
{
    public class DeviceFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (IsMobileDevice(HttpContext.Current))
                HttpContext.Current.Response.Redirect("http://m.raovat24.net");
        }
        
        private bool IsMobileDevice(HttpContext context)
        {
            if (context.Request.UserAgent != null)
            {
                string strUserAgent = context.Request.UserAgent.ToLower();

                if (context.Request.Browser.IsMobileDevice || strUserAgent.Contains("iphone") ||
                    strUserAgent.Contains("blackberry") || strUserAgent.Contains("mobile") ||
                    strUserAgent.Contains("windows ce") || strUserAgent.Contains("opera mini") ||
                    strUserAgent.Contains("palm"))
                {
                    return true;
                }
            }
            return false;
        }
    }
}